import 'package:ctrip_flutter/app/pages/home_page.dart';
import 'package:ctrip_flutter/app/pages/mine_page.dart';
import 'package:ctrip_flutter/app/pages/search_page.dart';
import 'package:ctrip_flutter/app/pages/travel_page.dart';
import 'package:flutter/material.dart';

class TabNavigator extends StatefulWidget {
  @override
  _TabNavigatorState createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<TabNavigator> {
  final PageController _controller = PageController(initialPage: 0);

  final Color _norColor = Colors.black26;
  final Color _delColor = Colors.amberAccent;
  int _index = 0;
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: <Widget>[
          HomePage(context), //首页
          SearchPage(), //搜索
          TravelPage(), //旅拍
          MinePage() //我的
        ],
//        physics: NeverScrollableScrollPhysics(),//PageView 禁止切换
        onPageChanged: (vales) {
          setState(() {
            _index = vales;
          });
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _index,
          onTap: (index) {
            _controller.jumpToPage(index);
            setState(() {
              _index = index;
              print(_index);
            });
          },
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.home,
                  color: _norColor,
                ),
                activeIcon: Icon(
                  Icons.home,
                  color: _delColor,
                ),
                title: Text(
                  "首页",
                  style: TextStyle(color: _index != 0 ? _norColor : _delColor),
                )),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.search,
                  color: _norColor,
                ),
                activeIcon: Icon(
                  Icons.search,
                  color: _delColor,
                ),
                title: Text(
                  "搜索",
                  style: TextStyle(color: _index != 1 ? _norColor : _delColor),
                )),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.camera_alt,
                  color: _norColor,
                ),
                activeIcon: Icon(
                  Icons.camera_alt,
                  color: _delColor,
                ),
                title: Text(
                  "旅拍",
                  style: TextStyle(color: _index != 2 ? _norColor : _delColor),
                )),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.account_circle,
                  color: _norColor,
                ),
                activeIcon: Icon(
                  Icons.account_circle,
                  color: _delColor,
                ),
                title: Text(
                  "我的",
                  style: TextStyle(color: _index != 3 ? _norColor : _delColor),
                ))
          ]),
    );
  }
}
